package de.reondo.jos;

import org.jgrapht.Graph;

public class PackageGraphStyler implements
		IGraphStyler<Package, PackageDependencyEdge> {

	private int maxNumberOfEdges;
	private Graph<Package, PackageDependencyEdge> graph;

	public PackageGraphStyler(Graph<Package, PackageDependencyEdge> graph) {
		this.graph = graph;
		Package maxEdgeVertex = GraphUtils.getVertexWithMaximumEdges(graph);
		maxNumberOfEdges = 0;
		if (maxEdgeVertex != null) {
			maxNumberOfEdges = graph.edgesOf(maxEdgeVertex).size();
		}
	}
	
	@Override
	public String getColorForVertex(Package vertex) {
		double d = graph.edgesOf(vertex).size() / (maxNumberOfEdges + 1.0) * 9;
		int i = ((int) Math.floor(d)) + 1;
		return ""+i;
	}

	@Override
	public String getVertexLabel(Package vertex) {
		return vertex.getName();
	}

	@Override
	public String getEdgeLabel(PackageDependencyEdge edge) {
		if (edge.getType().equals(PackageDependencyType.USES)) {
			return "\u00abuse\u00bb";
		}
		return edge.getType().getShortName();
	}

}
